package com.qk.controller;

import com.qk.common.Result;
import com.qk.utils.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator  aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws Exception {
        String filename = image.getOriginalFilename();
        String extend = filename.substring(filename.lastIndexOf('.'));
        String s = UUID.randomUUID() + extend;

        String upload = aliyunOSSOperator.upload(image.getBytes(), s);
        return Result.success(upload);


    }
}
